﻿using EnumHelper = QunProject.Model.EnumHelper;

namespace QunProject.Common
{
    /// <summary>
    /// 返回数据实体
    /// </summary>
    public class Result
    {
        /// <summary>
        /// 消息
        /// </summary>
        public string msg { get; set; }
        /// <summary>
        /// 是否成功
        /// </summary>
        public bool succ { get; set; }
        /// <summary>
        /// 消息代码
        /// </summary>
        public string code { get; set; }
        /// <summary>
        /// 数据
        /// </summary>
        public object data { get; set; }
        /// <summary>
        /// 数量（仅用于分页）
        /// </summary>
        public int count { get; set; }
        /// <summary>
        /// 构造函数
        /// [msg:string.Empty|succ:false|code:ConstantCode.Result.result_fail|data:null]
        /// </summary>
        public Result()
        {
            msg = string.Empty;
            succ = false;
            code = ConstantCode.Result.result_fail;
            data = null;
            count = 0;
        }
        /// <summary>
        /// 成功
        /// [succ:true|code:ConstantCode.Result.result_success]
        /// </summary>
        /// <param name="_data"></param>
        /// <param name="_msg"></param>
        public Result Success(object _data = null, string _msg = "执行成功")
        {
            msg = _msg;
            data = _data;
            code = ConstantCode.Result.result_success;
            succ = true;
            count = 0;
            return this;
        }
        /// <summary>
        /// 成功返回数据
        /// [succ:true|code:ConstantCode.Result.result_success]
        /// </summary>
        /// <param name="_count">总数量</param>
        /// <param name="_data">数据</param>
        /// <returns></returns>
        public Result SuccessReturnData(int _count, object _data = null, string _msg = "执行成功")
        {
            msg = _msg;
            data = _data;
            code = ConstantCode.Result.result_success;
            succ = true;
            count = _count;
            return this;
        }
        /// <summary>
        /// 失败
        /// [succ:false|code:ConstantCode.Result.result_fail|data:null]
        /// </summary>
        /// <param name="_msg"></param>
        public Result Fail(string _msg = "执行失败")
        {
            msg = _msg;
            data = null;
            code = ConstantCode.Result.result_fail;
            succ = false;
            count = 0;
            return this;
        }
        /// <summary>
        /// 异常
        /// [succ:false|code:ConstantCode.Result.result_fail|data:null]
        /// </summary>
        /// <param name="_msg"></param>
        public Result Error(string _msg = "执行错误")
        {
            msg = _msg;
            data = null;
            code = ConstantCode.Result.result_error;
            succ = false;
            count = 0;
            return this;
        }
        /// <summary>
        /// 登录过期
        /// [succ:false|code:ConstantCode.Result.result_login_outtime|data:null]
        /// </summary>
        /// <param name="_msg"></param>
        public Result OutTime(string _msg = "登录过期")
        {
            msg = _msg;
            data = null;
            code = ConstantCode.Result.result_login_outtime;
            succ = false;
            count = 0;
            return this;
        }
    }
}
